<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class About extends Sys_Controller {
    public function __construct()
    {
        parent::__construct();

        $this->load->Model('About_model');
        $this->load->library('form_validation');
    }

    public function AboutInfo()
    {
        $data['aboutModel']=$this->About_model->Get_About_First();
        $this->load->view('admin/about/aboutinfo.html',$data);
    }

    public function DelAbout()
    {
        $this->load->library('ajaxMsgModel');
        $about_id=$this->uri->segment(4);
        $res=$this->About_model->DelAbout_ById($about_id);
        if($res>0)
        {
            $this->ajaxmsgmodel->Msg='删除成功';
            $this->ajaxmsgmodel->Statu='ok';
            $this->ajaxmsgmodel->BackUrl=site_url('admin/about/aboutinfo');
        }
        else
        {
            $this->ajaxmsgmodel->Msg='删除失败';
            $this->ajaxmsgmodel->Statu='err';
        }
        echo(json_encode($this->ajaxmsgmodel));
    }

    public function Edit_About()
    {
        $valiRes= $this->form_validation->run('about_vali');
        $this->load->library('ajaxMsgModel');
        $aboutModel=new $this->About_model();
        if($valiRes)
        {
            $aboutModel->title=$this->input->post('title');
            $aboutModel->imgurl=$this->input->post('imgurl');
            $aboutModel->contents=$this->input->post('contents',false);
            if($this->input->post('mark')=="1")//修改
            {
                $aboutModel->about_id=$this->input->post('about_id');
                $res= $this->About_model->Edit_About($aboutModel);
                if($res>0)
                {
                    $this->ajaxmsgmodel->Msg='修改成功';
                    $this->ajaxmsgmodel->Statu='ok';
                    $this->ajaxmsgmodel->BackUrl=site_url('admin/about/aboutinfo');
                }
                else
                {
                    $this->ajaxmsgmodel->Msg='修改失败';
                    $this->ajaxmsgmodel->Statu='err';
                }
            }else{//添加
                $res= $this->About_model->Add_About($aboutModel);
                if($res>0)
                {
                    $this->ajaxmsgmodel->Msg='添加成功';
                    $this->ajaxmsgmodel->Statu='ok';
                    $this->ajaxmsgmodel->BackUrl=site_url('admin/about/aboutinfo');
                }
                else
                {
                    $this->ajaxmsgmodel->Msg='添加失败';
                    $this->ajaxmsgmodel->Statu='err';
                }
            }

        }else{
            $errors=  $this->form_validation->error_array();
            $this->ajaxmsgmodel->Msg='服务器验证失败:'.get_validate_errors($errors);;
            $this->ajaxmsgmodel->Statu='err';
            $this->ajaxmsgmodel->BackUrl=site_url('admin/about/aboutinfo');
        }
        echo(json_encode($this->ajaxmsgmodel));
    }


}
?>